fix(telegram): skip empty text in sendMessageDraft to prevent 400 spam#7398
Open
he-yufeng wants to merge 1 commit intoAstrBotDevs:masterfrom
Open
fix(telegram): skip empty text in sendMessageDraft to prevent 400 spam#7398he-yufeng wants to merge 1 commit intoAstrBotDevs:masterfrom
he-yufeng wants to merge 1 commit intoAstrBotDevs:masterfrom
Conversation
When streaming is enabled, markdownify() can produce empty strings for certain inputs (whitespace-only, formatting-only markdown). The draft sender loop then calls sendMessageDraft with empty text, which Telegram rejects with 'Text must be non-empty', flooding the log every 0.5s. Add an early return in _send_message_draft() when text is empty or whitespace-only. This matches WebChat's approach of skipping empty responses. Fixes AstrBotDevs#7353
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider updating the
_send_message_draftdocstring (and any type hints) to explicitly document that empty/whitespace-only text is ignored and that the function may return early without sending anything. - If
textcan be something other thanstr(e.g.,Noneor other falsy value), you may want to narrow the condition to a string check to avoid accidentally skipping non-string payloads that should be handled differently.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider updating the `_send_message_draft` docstring (and any type hints) to explicitly document that empty/whitespace-only text is ignored and that the function may return early without sending anything.
- If `text` can be something other than `str` (e.g., `None` or other falsy value), you may want to narrow the condition to a string check to avoid accidentally skipping non-string payloads that should be handled differently.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a guard clause in the _send_message_draft method within the Telegram platform source to prevent the processing of empty or whitespace-only messages. I have no feedback to provide as the implementation is correct and there were no review comments to evaluate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7353
When streaming output is enabled,
markdownify()can return empty strings for certain inputs (whitespace-only content, formatting-only markdown). The draft sender loop then callssendMessageDraftwith empty text, which Telegram rejects with "Text must be non-empty", flooding the log every 0.5s.Changes
Added an early return in
_send_message_draft()whentextis empty or whitespace-only. This matches WebChat's approach of skipping empty responses (webchat_event.pyline 200:if not r: continue).Test plan
Summary by Sourcery
Bug Fixes: